#include "Options.h"

Options::Options() {

}

Options::~Options() {

}

void Options::parseOptions(int argc, char* argv[]) {
	std::string options = "";
	std::string options1 = "ab:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:";
	std::string options2 = "";
	int count = 10;
	for (size_t i = 1; i < count; i++)
	{
		options2.append(std::to_string(i));
		options2.append(":");
	}

	options = options1 + options2;

	for (int i = 1; i < argc; ++i) {
		std::string arg = argv[i];
		if (arg.size() == 2 && arg[0] == '-') {
			char opt = arg[1];
			if (options.find(opt) != std::string::npos) {
				// 在这里处理选项字符 opt
				// 可以调用 setValue 函数来设置对应的参数值
				// 例如：
				setValue(opt, argv[i + 1]); // 假设参数值紧跟在选项字符后面
				std::cerr << opt << std::endl;
				++i; // 跳过参数值
			}
			else {
				std::cerr << "Unknown option: " << arg << std::endl;
				exit(1);
			}
		}
		else {
			// 在这里处理非选项参数
			exit(1);
		}
	}
}

void Options::printOptions() {
	for (const auto& kv : values) {
		std::cout << "Option: -" << kv.first << ", Value: " << kv.second << std::endl;
	}
}

void Options::setValue(char option, const std::string& value) {
	values[option] = value;
}

void Options::printUsageAndExit(const char* programName) {
	std::cout << "Usage: " << programName << " -a <value1> -b <value2> ... -z <value26>" << std::endl;
	exit(1);
}

// 获取查询结果
std::unordered_map<char, std::string> Options::getValues() const {
	return values;
}